package com.tanhua.dubbo.api.db;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.tanhua.domain.db.QuizStar;
import com.tanhua.dubbo.mapper.QuizStarMapper;
import org.apache.dubbo.config.annotation.Service;
import org.springframework.beans.factory.annotation.Autowired;

import java.util.HashMap;
import java.util.Map;

@Service
public class QuizStarApiImpl implements QuizStarApi{

    @Autowired
    private QuizStarMapper quizStarMapper;
    /**
     * 根据用户id查询用户星级
     * @param userId
     * @return 用户星级
     */
    @Override
    public Integer queryUserStar(Long userId) {
        Integer star = 2;
        QueryWrapper query = new QueryWrapper();
        query.eq("user_id",userId);
        QuizStar quizStar = quizStarMapper.selectOne(query);
        if(quizStar==null) return star;
        return quizStar.getUserStar();
    }


    /**
     * 根据用户id,得到星级表记录
     *
     * @param userId
     * @return
     */
    @Override
    public QuizStar queryStarById(Long userId) {
        QueryWrapper<QuizStar> wrapper = new QueryWrapper<>();
        wrapper.eq("user_id", Integer.parseInt(userId.toString()));
        return quizStarMapper.selectOne(wrapper);
    }

    /**
     * 保存星级数据
     *
     * @param quizStar
     */
    @Override
    public void saveQuizStar(QuizStar quizStar) {
        quizStarMapper.insert(quizStar);
    }

    /**
     * 更新星级
     * @param quizStar
     */
    @Override
    public void updateQuizStar(QuizStar quizStar) {
        quizStarMapper.updateById(quizStar);
    }
}
